#include <opencv2\core\core.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include <iostream>
#include "myOpenCVLIB\myheader.h"

using namespace std;  
using namespace cv; 

void showImg(Mat img, char * name){
	namedWindow(name);
	imshow(name,img);
	waitKey();
}


int main(){

	Mat img, img_gray,grad;
	int scale = 1;
	int delta = 0;
	int depth = CV_16S;

	img = imread(LENA);
	if(!img.data){
		cout << "cannot load img";
		getchar();
		return -1;
	}

	showImg(img,"img");

	GaussianBlur(img,img,Size(3,3),0,0,BORDER_DEFAULT);

	showImg(img,"GaussianBlur");

	cvtColor(img,img_gray,CV_RGB2GRAY);
	showImg(img_gray,"img_gray");
	
	Mat gradX, gradY, absGradX, absGradY;

	Scharr( img_gray, gradX, depth, 1, 0, scale, delta, BORDER_DEFAULT );
	//Sobel(img_gray, gradX,depth,1,0,3,scale,delta,BORDER_DEFAULT);
	showImg(gradX,"gradX");
	convertScaleAbs(gradX,absGradX);
	showImg(absGradX,"absGradX");


	//Scharr( img_gray, gradY, depth, 1, 0, scale, delta, BORDER_DEFAULT );
	Sobel(img_gray, gradY,depth,1,0,3,scale,delta,BORDER_DEFAULT);
	showImg(gradY,"gradY");
	convertScaleAbs(gradY,absGradY);
	showImg(absGradY,"absGradY");

	addWeighted(absGradX, 0.5, absGradY, 0.5, 0, grad);


	showImg(grad,"grad");




	return 0;
}